package br.com.automed.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import br.com.automed.jpautil.JPAUtil;

@FacesConverter(value="convertEntity")
public class ConvertEntity implements Converter {

	public Object getAsObject(FacesContext context, UIComponent component, String value) {
		String[] vetor = value.split(";");
		
		Class<?> classe = null;
		try {
			classe = Class.forName(vetor[0]);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		return JPAUtil.get(classe, vetor[1]);
	}

	public String getAsString(FacesContext arg0, UIComponent arg1, Object value) {
		
		return value != null ? value.toString() : null;
	}

}
